import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.*;


public class UiSwing {
	public static void main(String[] args){
		UiFrame frame = new UiFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}

class UiFrame extends JFrame{
	public UiFrame(){
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		this.setBounds(screenSize.width/4 ,screenSize.height/4,screenSize.width/2,screenSize.height/2);
	//	Image img = kit.getImage("C:/Users/stefano/Desktop/corejava7/v1/v1ch7/CenteredFrameTest/icon.gif");
	//	this.setIconImage(img);
		this.setTitle("HORSE RACING");
		BackgroundedFrame p = new BackgroundedFrame();
		this.add(p);
//		ButtonIntro b = new ButtonIntro();
//		this.add(b);
		//pack();
		
		System.out.println();
	}
}
/*
class ButtonIntro extends JPanel{
	public ButtonIntro(){
		this.setLayout(new GridLayout(4,1,33,0));
		JButton gioca = new JButton("Gioca");
		JButton opzioni = new JButton("Opzioni");
		JButton guida = new JButton("Guida");
		JButton esci = new JButton("Esci");
		add(gioca);
		add(opzioni);
		add(guida);
		add(esci);
	}
	
}*/

class BackgroundedFrame extends JPanel{
	private Image img;
	
	public BackgroundedFrame() {
		this.setLayout(new FlowLayout(FlowLayout.LEFT));
		img = Toolkit.getDefaultToolkit().createImage("src/CorsaCavalli/intro.jpg");
		//Dimension FrameDimension = Toolkit.getDefaultToolkit()
//		ButtonIntro b = new ButtonIntro();
//		this.add(b);
		loadImage(img);
	}

	
	private void loadImage(Image img) {
	    try {
	    	MediaTracker track = new MediaTracker(this);
	    	track.addImage(img, 0);
	    	track.waitForID(0);
	    }
	    catch (InterruptedException e) {
	    	e.printStackTrace();
	    }
	}

	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		setOpaque(false);
		//this.
		System.out.println();
		g.drawImage(img, 0, 0, this.getBounds().width, this.getBounds().height, Color.BLACK, this);
	}
}